package com.zw.xxh.udp;

import com.zw.xxh.rtp.DataPacket;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.concurrent.atomic.AtomicInteger;

public class UdpServerHandler extends ChannelInboundHandlerAdapter {

    final AtomicInteger counter = new AtomicInteger(0);

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        DataPacket packet = (DataPacket) msg;
//        ByteBuf byteBuf = (ByteBuf) msg;
//        int length = byteBuf.readableBytes();
//        byte[] da = new byte[length];
//        byteBuf.readBytes(da);
//        System.out.println("receive: " + Arrays.toString(da));
        System.out.println("第 " + counter.incrementAndGet() + " 次收到（package size = " + packet.getDataSize() + " ) data is" + packet);
        ;
    }
}
